<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="UTF-8"%>
<%@page import="com.jspsmart.upload.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<jsp:useBean id="db" class="connBean.ConnDB" scope="page"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>保存用户</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <%
    SmartUpload upload =new SmartUpload();
  upload.initialize(pageContext);
  upload.setMaxFileSize(2000000000);
  upload.setAllowedFilesList("jpg,JPG,gif");
  upload.setDeniedFilesList("exe,bat,jsp,js,htm,html");
  upload.upload();
  upload.save("/images");
 
    request.setCharacterEncoding("UTF-8");
    
    String username=upload.getRequest().getParameter("username");
    String password=upload.getRequest().getParameter("password");
    String header=upload.getFiles().getFile(0).getFileName();
    String telphone=upload.getRequest().getParameter("telphone");
    String question=upload.getRequest().getParameter("question");
    String answer=upload.getRequest().getParameter("answer");
    String address=upload.getRequest().getParameter("address");
    String email=upload.getRequest().getParameter("email");
    db.OpenConn();
    db.createStmt();
    String sql="insert into customer(c_name,c_pass,c_header,c_phone,c_question,c_answer,c_address,c_email) values('"+username+"','"+password+"','"+header+"','"+telphone+"','"+question+"','"+answer+"','"+address+"','"+email+"')";
    System.out.println(sql);
    int result=db.Update(sql);
    db.closeStmt();
    db.closeConn();
    if(result==1){
    session.setAttribute("username",username);
    response.sendRedirect("index.jsp");//执行插入成功跳转
    }else{
    %>
      注册失败，3秒后重新注册。
    <%
    response.setHeader("Refresh","3;URL=addUser.jsp");}//执行插入失败跳转
    %>
  </body>
</html>
